package com.neusoft.controller;

import com.neusoft.domain.Category;
import com.neusoft.domain.Result;
import com.neusoft.domain.ResultPage;
import com.neusoft.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/categorys")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/findCategoryByPage")
    public Result<ResultPage<Category>> findCategoryByPage(Integer page, Integer pageSize, String categoryName,Integer businessId){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        ResultPage<Category> resultPage = categoryService.findCategoryByPage(page,pageSize,categoryName,businessId);
        // 3. 响应数据给前端
        return Result.success(resultPage);
    }
    @PostMapping("/saveCategory")
    public Result saveCategory(@RequestBody Category category){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        categoryService.saveCategory(category);
        return Result.success();
    }
    @PutMapping("/updateCategory")
    public Result updateCategory(@RequestBody Category category){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        categoryService.updateCategory(category);
        // 3. 相应数据给前端
        return Result.success();
    }

    @DeleteMapping("/deleteCategory/{id}")
    public Result deleteCategory(@PathVariable Integer id){
        // 1. 接收参数
        // 2. 调用service层实现业务逻辑处理
        categoryService.deleteCategory(id);
        // 3. 相应数据给前端
        return Result.success();
    }

}
